package com.example.sicnuaccountingapp.ui.category

import android.view.LayoutInflater
import android.view.ViewGroup
import androidx.recyclerview.widget.RecyclerView
import com.example.sicnuaccountingapp.databinding.ItemIconBinding

class IconPickerAdapter(
    private val icons: List<IconItem>,
    private val onIconSelected: (IconItem) -> Unit
) : RecyclerView.Adapter<IconPickerAdapter.IconViewHolder>() {

    class IconViewHolder(
        private val binding: ItemIconBinding,
        private val onIconSelected: (IconItem) -> Unit
    ) : RecyclerView.ViewHolder(binding.root) {
        fun bind(icon: IconItem) {
            binding.iconImage.setImageResource(icon.resourceId)
            binding.root.setOnClickListener {
                onIconSelected(icon)
            }
        }
    }

    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): IconViewHolder {
        val binding = ItemIconBinding.inflate(
            LayoutInflater.from(parent.context),
            parent,
            false
        )
        return IconViewHolder(binding, onIconSelected)
    }

    override fun onBindViewHolder(holder: IconViewHolder, position: Int) {
        holder.bind(icons[position])
    }

    override fun getItemCount() = icons.size
}

data class IconItem(
    val resourceId: Int,
    val name: String
) 